package com.ts.base;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

/**
 * 继承CommandLineRunner 输出测试信息
 */

@Slf4j
@SpringBootApplication
public class BaseApplication implements CommandLineRunner {

	//protected static Logger logger=LoggerFactory.getLogger(BaseApplication.class);

	@Autowired
	private DataSource dataSource;

	public static void main(String[] args) {
		SpringApplication.run(BaseApplication.class, args);
	}

	@Override
	public void run(String... args) throws Exception {
		//输出启动信息
		showConnection();
	}

	private void showConnection() throws SQLException {
		log.info("data source info:\n");
		log.info(dataSource.toString());
		Connection conn =dataSource.getConnection();
		log.info(conn.toString());
		conn.close();

	}
}
